import request from '@/utils/request.js'
import {IPFS_PUBLIC_URL,IPFS_API_KEY ,IPFS_SECRET_API_KEY} from "@/utils/config.js"
// IPFS 公共网关 开始
//IPFS传JSON格式数据
const IPFS_JSON_UPLOAD_URL = "https://api.pinata.cloud/pinning/pinJSONToIPFS"
//IPFS传文件
const IPFS_FILE_UPLOAD_URL = "https://api.pinata.cloud/pinning/pinFileToIPFS"
// const IPFS_PUBLIC_URL = "https://chat.mypinata.cloud/ipfs/"
// const IPFS_API_KEY = "71ec3c18b175d5439b3c"
// const IPFS_SECRET_API_KEY = "a4dc5b04a67b39492bf69ee24ea38b080ebd0874a18001a4457bfa5547be9ddb"
const getLatest = (Symbol) => {
  return request.get('https://currencies.apps.grandtrunk.net/getlatest/USD/' + Symbol)
}
const getComponey = (number)=> {
  return request.get('https://www.kuaidi100.com/autonumber/autoComNum?text=' + number)
}
// 上传文件
const upload = (file) => {
  const formData = new FormData()
  formData.append('file', file)
  return request.post(IPFS_FILE_UPLOAD_URL, formData, {
    headers: {
      pinata_api_key: IPFS_API_KEY,
      pinata_secret_api_key: IPFS_SECRET_API_KEY
    }
  })
}
// 上传json对象存储
const jsonUpload = (params) => {
  return request.post(IPFS_JSON_UPLOAD_URL, params, {
    headers: {
      pinata_api_key: IPFS_API_KEY,
      pinata_secret_api_key: IPFS_SECRET_API_KEY
    }
  })
}
// 获取json对象
const getJson = (cid) => {
  return request.get(IPFS_PUBLIC_URL + cid)
}
const getOnline = ()=>{
  return request.get('https://www.youtube.com/')
}





export { getComponey, getLatest, upload, jsonUpload, getJson, IPFS_PUBLIC_URL, getOnline }